#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
pair<int, int>pr[N];
int diff[N], sum[N], ans = 0;
int main() {
    int n, m; cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        diff[a]++, diff[b + 1]--;
        pr[i] = { a,b };
    }
    for (int i = 1; i <= n; i++) {
        diff[i] += diff[i - 1];/
        sum[i] += sum[i - 1] + (diff[i] <= 1);/
        if (diff[i] == 0) ans++;
    }
    for (int i = 0; i < m; i++)cout << sum[pr[i].second] - sum[pr[i].first - 1] + ans << endl;
    return 0;
}